package com.learning.dubbo.service.context.provider;

import com.learning.dubbo.service.context.api.GreetingsService;
import org.apache.dubbo.rpc.RpcContext;

/**
 * ClassName: Consumer
 * Description: 消费客户端
 * Date: 2020/6/15 13:43 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
public class GreetingsServiceImpl implements GreetingsService {
    @Override
    public String sayHi(String name) {

        // 本端是否为提供端，这里会返回true
        RpcContext context = RpcContext.getContext();

        boolean isProviderSide = context.isProviderSide();
        System.out.println(isProviderSide);

        // 获取调用方IP地址
        String clientIP = context.getRemoteHost();
        System.out.println(clientIP);

        // 获取当前服务配置信息，所有配置信息都将转换为URL的参数
        String application = context.getUrl().getParameter("application");
        System.out.println(application);

        // 隐式参数：服务提供方端获取隐式参数
        String name1 = context.getAttachment("name");
        System.out.println(name1);

        System.out.println("******************");
        return "hi, " + name;
    }
}